﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace orm.Migrations
{
    public partial class UpdatOrg : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(@"
drop view OrgnizationView;
");
            migrationBuilder.Sql(@"
create view OrgnizationView as
select p.policy_id as id, p.customer_name as name, 0 as type_id, null as pid
from TGS_T_D_POLICY p 
union
select p1.project_id as id,  p1.project_name as name, 1 as type_id, p1.policy_id  as pid from TGS_T_D_Project p1 join TGS_T_D_POLICY p on p.policy_id == p1.policy_id 
union 
select p2.site_id as id, p2.site_name as name, 2 as type_id, p1.project_id  as pid from TGS_T_D_SITE p2 join TGS_T_D_Project p1 on p2.project_id == p1.project_id 
union
select p3.well_id as id, p3.well_common_name as name, 3 as type_id, p2.site_id as pid from TGS_T_D_Well p3 join TGS_T_D_SITE p2 on p3.site_id == p2.site_id
union
select p4.wellbore_id as id, p4.wellbore_name as name, 4 as type_id, p3.well_id as pid from TGS_T_D_WellBore p4 join TGS_T_D_Well p3 on p4.well_id == p3.well_id
union
select p5.scenario_id as id, p5.name as name, 5 as type_id, p4.wellbore_id as pid from TGS_T_D_SurveyScenario p5 join TGS_T_D_WellBore p4 on p5.wellbore_id == p4.wellbore_id;
");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {

        }
    }
}
